<?php

require_once 'phpmoko/ui/Form/FormBase.php';

class CheckBox extends FormBase
{
	private $enabled = true;
	private $label;
	private static $lastId = 0;
	
	function __construct($label)
	{
		parent::__construct();
		
		$this->label = $label;
		
		$this->setStyleName('pmk-CheckBox');
	}

	/**
	 * Sets the checkbox whether is enabled or not
	 * @param bool $enabled
	 */
	function setEnabled($enabled)
	{
		$this->enabled = $enabled;
	}

	/**
	 * Sets the input element name
	 * @param <type> $name
	 */
	function setName($name)
	{
		$this->name = $name;
	}
	
	function toString()
	{
		$str = '<span';
		
		if ($this->style != null)
			$str .= ' class="'.$this->style;

		if (!$this->enabled)
			$str .= ' pmk-CheckBox-disabled';

		$str .= '">';
		
		$str .= '<input';

		if (!$this->enabled)
			$str .= ' disabled="disabled"';

		if ($this->name != null)
			$str .= ' name="'.$this->name.'"';

		if ($this->id == null)
		{
			$this->id = 'pmk-uid-'.self::$lastId;
			self::$lastId++;
		}
			
		$str .= ' id="'.$this->id.'"';
		$str .= ' type="checkbox"';
		$str .= '>';
		
		$str .= '<label for="'.$this->id.'">'.$this->label.'</label>';
		
		$str .= '</span>';

		return $str;
	}
}
?>